package com.yeci.config;

import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @description: Sa-Token相关配置
 * @author: yeci
 * @date: 2021/8/19 11:30
 **/
@Configuration
public class SaTokenConfig implements WebMvcConfigurer {
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    /*registry.addInterceptor(new SaRouteInterceptor((req, resp, handler) -> { \
      // 获取配置文件中的白名单路径
      List<String> ignoreUrls = new ArrayList<>(); \
      ignoreUrls.add( ""); \
      // 登录认证：除白名单路径外均需要登录认证
      SaRouter.match(Collections.singletonList("/**"), ignoreUrls, StpUtil::checkLogin); \
      // 登录验证 -- 排除多个路径 \
      // SaRouter.match(Arrays.asList("/**"), Arrays.asList("/sys/login", "/sysUser/addUser"), () -> StpUtil.checkLogin());\
    })).addPathPatterns("/**");*/
  }
}
